package com.chen.blue.converter.system;

import com.chen.blue.domain.dto.system.RoleDto;
import com.chen.blue.domain.dto.system.UserDto;
import com.chen.blue.domain.dto.system.update.RoleDtoEdit;
import com.chen.blue.domain.dto.system.update.UserDtoEdit;
import com.chen.blue.domain.model.system.RoleModel;
import com.chen.blue.domain.model.system.UsersModel;
import com.chen.blue.domain.vo.system.RoleVo;
import com.chen.blue.domain.vo.system.UserVo;
import org.springframework.cglib.beans.BeanCopier;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * Created By CLT On 2024/4/27.
 */
@SuppressWarnings("all")
public abstract class RoleConverter {

    private static final BeanCopier modelToVo = BeanCopier.create(RoleModel.class, RoleVo.class, false);
    private static final BeanCopier dtoToModel = BeanCopier.create(RoleDto.class, RoleModel.class, false);
    private static final BeanCopier dtoEditToModel = BeanCopier.create(RoleDtoEdit.class, RoleModel.class, false);


    /**
     * model->vo
     *
     * @param model
     * @return
     */
    public static RoleVo modelToVo(RoleModel model) {
        if (Objects.isNull(model)) {
            return null;
        }
        RoleVo roleVo = new RoleVo();
        modelToVo.copy(model, roleVo, null);
        return roleVo;
    }

    /**
     * model->volist
     *
     * @param modelList
     * @return
     */
    public static List<RoleVo> modelToVoList(List<RoleModel> modelList) {
        if (modelList.size() == 0) {
            return null;
        }

        List<RoleVo> roleVoList = new ArrayList<>();
        for (RoleModel roleModel : modelList) {
            roleVoList.add(modelToVo(roleModel));
        }

        return roleVoList;

    }

    /**
     * dto->model
     *
     * @param userDto
     * @return
     */
    public static RoleModel dtoToModel(RoleDto roleDto) {

        if (Objects.isNull(roleDto)) {
            return null;
        }

        RoleModel roleModel = new RoleModel();
        dtoToModel.copy(roleDto, roleModel, null);
        return roleModel;

    }

    /**
     * editDto->model
     *
     * @param userDtoEdit
     * @return
     */
    public static RoleModel dtoEditToModel(RoleDtoEdit roleDtoEdit) {

        if (Objects.isNull(roleDtoEdit)) {
            return null;
        }

        RoleModel roleModel = new RoleModel();
        dtoEditToModel.copy(roleDtoEdit, roleModel, null);
        return roleModel;

    }


}
